package com.distribute.framework.model;

import com.distribute.framework.core.web.helper.Utils;
import java.lang.reflect.Field;
import java.util.Date; 
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

import javax.annotation.Resource;

import com.distribute.framework.core.web.util.Page;
import com.distribute.framework.core.lang.*; 
import com.distribute.framework.core.web.helper.WebHelper.LzMap;
import com.distribute.framework.core.util.Function;
import com.distribute.framework.core.util.IbatisMap;
import com.distribute.framework.config.*;
import com.distribute.framework.plugin.*;

@namespace("api/apitype")
public @caption("API分类") @database(DatabaseNames.distribute_sys) @source("distribute_sys") @table("srv_api_type") class SrvApiType implements java.io.Serializable
{
	private static final long serialVersionUID = 1l;
	private @caption("编号") @column("sat_id")    @primary  @notnull  @note("  ") Long satId;// 主键 非空     
	private @caption("分类名称") @column("sat_name")     @notnull  @note("  ") String satName;// 非空     
	private @caption("所属分类") @column("sat_parent")   @hidden   @notnull  @relate("$satParent") @RelateClass(SrvApiType.class)  @note("  ") Long satParent;// 非空     
 	private transient SrvApiType $satParent;//关联对象[API分类]
	private @caption("分类标识") @column("sat_flag")      @note("  ") String satFlag;//     
	private @caption("修改时间") @column("sat_update_time")     @notnull  @note("  ") Date satUpdateTime;// 非空     
	private @caption("添加时间") @column("sat_add_time")     @notnull  @note("  ") Date satAddTime;// 非空     
	private @caption("状态") @column("sat_status")     @notnull  @note(" 1:正常 0:无效  ") Short satStatus;// 非空 1:正常 0:无效     
	 
	//默认构造函数
	public SrvApiType(){ 
	
	}
	
	//主键构造函数
	public SrvApiType(Long id){
		this.satId = id;
	}
	
	/**所有字段构造函数 
	 SrvApiType(
	 	Utils.getString("satName")//分类名称 [非空]
	 	,Utils.getLong("satParent")//所属分类 [非空]
	 	,Utils.getString("satFlag")//分类标识
	 	,Utils.getDate("satUpdateTime")//修改时间 [非空]
	 	,Utils.getDate("satAddTime")//添加时间 [非空]
	 	,Utils.getShort("satStatus")//状态 [非空]
	 )
	**/
	public SrvApiType(String satName,Long satParent,String satFlag,Date satUpdateTime,Date satAddTime,Short satStatus){
		this.satName=satName;
		this.satParent=satParent;
		this.satFlag=satFlag;
		this.satUpdateTime=satUpdateTime;
		this.satAddTime=satAddTime;
		this.satStatus=satStatus;
	}
	
	//设置非空字段
	public SrvApiType setNotNull(String satName,Long satParent,Date satUpdateTime,Date satAddTime,Short satStatus){
		this.satName=satName;
		this.satParent=satParent;
		this.satUpdateTime=satUpdateTime;
		this.satAddTime=satAddTime;
		this.satStatus=satStatus;
		return this;
	}
	/** 编号 [非空]       **/
	public SrvApiType satId(Long satId){
		this.satId = satId;
		this.setSeted(F.satId);
		return this;
	}
	/** 分类名称 [非空]       **/
	public SrvApiType satName(String satName){
		this.satName = satName;
		this.setSeted(F.satName);
		return this;
	}
	/** 所属分类 [非空] [SrvApiType]      **/
	public SrvApiType satParent(Long satParent){
		this.satParent = satParent;
		this.setSeted(F.satParent);
		return this;
	}
	/** 分类标识        **/
	public SrvApiType satFlag(String satFlag){
		this.satFlag = satFlag;
		this.setSeted(F.satFlag);
		return this;
	}
	/** 修改时间 [非空]       **/
	public SrvApiType satUpdateTime(Date satUpdateTime){
		this.satUpdateTime = satUpdateTime;
		this.setSeted(F.satUpdateTime);
		return this;
	}
	/** 添加时间 [非空]       **/
	public SrvApiType satAddTime(Date satAddTime){
		this.satAddTime = satAddTime;
		this.setSeted(F.satAddTime);
		return this;
	}
	/** 状态 [非空]   1:正常 0:无效     **/
	public SrvApiType satStatus(Short satStatus){
		this.satStatus = satStatus;
		this.setSeted(F.satStatus);
		return this;
	}
	
	
	/**
	* 克隆对象
	**/
	public SrvApiType clone(){
		SrvApiType clone = new SrvApiType();
		clone.satName=this.satName;
		clone.satParent=this.satParent;
		clone.satFlag=this.satFlag;
		clone.satUpdateTime=this.satUpdateTime;
		clone.satAddTime=this.satAddTime;
		clone.satStatus=this.satStatus;
		return clone;
	}
	/**
	* 清除缓存
	**/
	public void clear(){
		Cache.clearObject(SrvApiType.M.class);
		Cache.clearValue(SrvApiType.M.class);
		Cache.deleteObject(SrvApiType.class, this.getId());
	}
	
	/**
	* 清除缓存
	**/
	public static void clear(Long id){
		Cache.clearObject(SrvApiType.M.class);
		Cache.clearValue(SrvApiType.M.class);
		Cache.deleteObject(SrvApiType.class, id);
	}
	
	
	/**
	 * 根据ID取API分类
	 * @param id
	 * @return
	 */
	public static @api SrvApiType get(Long id){		
		return getSrvApiTypeById(id);
	}
	/**
	 * 设置ID
	 * @param id
	 * @return
	 */
	public void setId(Long id){		
		this.satId = id;
	}
	
	/**
	 * 获取所有API分类
	 * @return
	 */
	public static @api List<SrvApiType> list(Map params,Integer size){
		return getSrvApiTypeList(params,size);
	}
	/**
	 * 获取API分类分页
	 * @return
	 */
	public static @api Page<SrvApiType> page(Integer page,Integer size,Map params){
		return getSrvApiTypePage(page, size , params);
	}
	
	
	/**
	 * 根据查询条件取API分类
	 * @param params
	 * @return
	 */
	public static @api SrvApiType Get(Map params){
		return getSrvApiType(params);
	}
	/**
	 * 获取API分类数
	 * @return
	 */
	public static @api Long count(Map params){
		return getSrvApiTypeCount(params);
	}
	/**
	 * 获取API分类数
	 * @return
	 */
	public static @api <T> T eval(String eval,Map params){
		return getSrvApiTypeEval(eval,params);
	}
	/**
	 * 获取API分类图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey){
		return getSrvApiTypeStats(params,sumKey,groupKey,-1);
	}
	/**
	 * 获取API分类图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey,int dateType){
		return getSrvApiTypeStats(params,sumKey,groupKey,dateType);
	}
	
	/**
	 * 根据ID取API分类
	 * @param id
	 * @return
	 */
	public static @api SrvApiType getSrvApiTypeById(Long id){		
		return getSrvApiTypeDao().getSrvApiTypeById(id);
	}
	/**
	 * 获取id
	 * @return
	 */
	public Long getId(){
		return this.satId;
	}
	
	
	/**
	 * 根据ID取API分类的标识键值
	 * @param id
	 * @return
	 */
	public static @api String getKeyValue(Object key){
		Long id = Utils.parseLong(key);	
		if(id==null || id.longValue()==0 ){
			return "[无]";
		}
		String value = null;
		value = Cache.getValue(SrvApiType.class, id);
		if(value==null){
			SrvApiType srvApiType = get(id);
			if(srvApiType!=null){
				String strValue = srvApiType.getSatName$();
				if(!"SatName".equals("SatName"))
					strValue+="("+srvApiType.getSatName$()+")";
				Cache.setValue(SrvApiType.class, id ,strValue);
				value = strValue;
			}else{
				Cache.setValue(SrvApiType.class, id ,"{"+id+"}",30);
				value = "{"+id+"}";
			}
		}
		/************LAZY3Q_ID_KEYVALUE************/
		/************LAZY3Q_ID_KEYVALUE************/
		return value;
	}	
	
	
	/**
	 * 获取当前对象的键值
	 * @return
	 */
	public String getKeyValue(){
		/************LAZY3Q_CODE_KEYVALUE************/
		/************LAZY3Q_CODE_KEYVALUE************/
		String keyValue = this.getSatName$();
		if(!"SatName".equals("SatName"))
			keyValue+="("+this.getSatName$()+")";
		return keyValue;
	}
	
	
	/**
	 * 根据关键字精确查询API分类对象
	 * @return
	 */
	public static @api SrvApiType find(String key){
		if(Utils.empty(key))return null;
		Map params = new HashMap();
		if(key.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
			params.put("satId", key.toLowerCase().replaceFirst("id:", ""));					
		else{//按标识查询，精确查询
			String strDefinex = "";
			strDefinex+=" or sat_name = '"+key.replaceAll("'", "''")+"'";
			strDefinex="(2=1 "+strDefinex+")";
			params.put("definex",strDefinex);
		}
		/************LAZY3Q_CODE_FIND************/
		/************LAZY3Q_CODE_FIND************/
		return SrvApiType.getSrvApiType(params);
	}
	
	
	/**
	 * 根据关键字查询API分类
	 * @return
	 */
	public static @api List<Map> query(String key,int size,Map params,Boolean bObject){
		if(Utils.empty((String)params.get("asc")) && Utils.empty((String)params.get("desc")))//如果未传入排序字段
			params.put("desc","sat_id");//那么，默认以主键降序，传给Dao层
		String strTerm=key;		
		if(!Utils.empty(strTerm)){
			if(strTerm.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
				params.put("satId", strTerm.toLowerCase().replaceFirst("id:", ""));					
			else//按标识查询，模糊查询请带%
			{
				String strDefinex = "";
				strDefinex+=" or sat_name like '%"+strTerm.replaceAll("'", "''")+"%'";
				strDefinex="(2=1 "+strDefinex+")";
				params.put("definex",strDefinex);
			}
		}
		/************LAZY3Q_CODE_QUERY************/
		/************LAZY3Q_CODE_QUERY************/
			
		List<SrvApiType> list = page(0,size,params).getResult();
		
		/**
		* OK!取到数据拼成放入Map中，[{value,text,object:{...}},...]
		* value:数据ID，text:数据标识,object,整个对象
		**/
		List<Map> result = new java.util.ArrayList();
		for(SrvApiType srvApiType:list){
			Map map = new HashMap();
			map.put("key",srvApiType.getSatId().toString());
			map.put("value", Utils.js(srvApiType.getKeyValue()));
			if(bObject==true)
				map.put("object",srvApiType);
			result.add(map);
		}
		/************LAZY3Q_AFTER_QUERY************/
		/************LAZY3Q_AFTER_QUERY************/
		
		return result;
	}
	
	
	
	/**
	 * 获取所有API分类
	 * @return
	 */
	public static @api List<SrvApiType> getSrvApiTypeList(Map params,Integer size){
		return getSrvApiTypeDao().getSrvApiTypeList(params,0,size);
	}
	
	/**
	 * 获取API分类分页
	 * @return
	 */
	public static @api Page<SrvApiType> getSrvApiTypePage(Integer page,Integer size,Map params){
		if(page==null)page=0;
		if(size==null)size=20;
		return getSrvApiTypeDao().getSrvApiTypePage(page, size , params);
	}
	
	/**
	 * 根据查询条件取API分类
	 * @param params
	 * @return
	 */
	public static @api SrvApiType getSrvApiType(Map params){
		return getSrvApiTypeDao().getSrvApiType(params);
	}
	
	/**
	 * 保存一个API分类
	 * @param srvApiType
	 * @return
	 */
	public static @api SrvApiType saveSrvApiType(SrvApiType srvApiType){
		return getSrvApiTypeDao().saveSrvApiType(srvApiType);
	}
	
	/**
	 * 根据条件更新API分类
	 * @param values
	 * @param params
	 */
	public static @api int updateSrvApiTypeByConfirm(Map values, Map params){
		return getSrvApiTypeDao().updateSrvApiTypeByConfirm(values,params);
	}
	
	/**
	 * 修改一个API分类
	 * @param srvApiType
	 * @return
	 */
	public static @api int updateSrvApiType(SrvApiType srvApiType){
		return getSrvApiTypeDao().updateSrvApiType(srvApiType);
	}
	
	/**
	 * 更新API分类非空字段
	 * @param srvApiType
	 */
	public static @api int updateSrvApiType$NotNull(SrvApiType srvApiType){
		return getSrvApiTypeDao().updateSrvApiType$NotNull(srvApiType);
	}
	
	/**
	 * 获取API分类数
	 * @return
	 */
	public static @api Long getSrvApiTypeCount(Map params){
		return getSrvApiTypeDao().getSrvApiTypeCount(params);
	}
		
		
	/**
	 * 获取API分类自定义求和表达式,比如求和:eval="sum(id)"
	 * @return
	 */	
	public static @api <T> T getSrvApiTypeEval(String eval,Map params){
		return getSrvApiTypeDao().getSrvApiTypeEval(eval,params);
	}
	/**
	 * 获取API分类图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> getSrvApiTypeStats(Map params,C sumKey,C groupKey,int dateType){
		//TODO:图表统计功能未实现
		
		Map<String,Object> groups=new HashMap();//要分组的字段
		Map<String,Object> sums=new HashMap();//要统计的字段
		
		String[][] dateFormats=new String[][]{
				null,
				new String[]{"%Y","yyyy年","Y"},
				new String[]{"%Y-%m","yyyy年MM月","M"},
				new String[]{"%Y%U","yyyy年第ww周","W"},
				new String[]{"%Y-%m-%d","yyyy年MM月dd日","D"},
				new String[]{"%Y-%m-%d %H","yyyy年MM月dd日 HH点","H"},
				new String[]{"%m","MM月"},
				new String[]{"%d","dd号"},
				new String[]{"%H","HH点"} 
		};
		
		//获取要分组的字段，放入Map中
		if(dateType>0){
			groups.put(groupKey.toString(),"DATE_FORMAT({key},'"+dateFormats[dateType][0]+"')");
		}else{
			groups.put(groupKey.toString(),"{key}");
		}
		if(dateType<6 && dateType>0){ 
			params.put("asc", groupKey.toString()); 
			if(params.get(groupKey.name()+"Start")==null){
				params.put(groupKey.name()+"Start", Utils.date(new Date(), -24, dateFormats[dateType][2]));
			}
		}
		
		
		//获取要统计的字段，放入Map中
		if(sumKey.toString().equals("count")){
			sums.put(sumKey.toString(),"count(*)");
		}else{
			sums.put(sumKey.toString(),"sum({key})");
		}
		
		List<Map> list = getSrvApiTypeDao().getSrvApiTypeStats(params,groups,sums);
		
		List<Map> result = new ArrayList();
		for(Map m:list){
			Map map = new HashMap();
			Object value = m.get(sumKey.toString());
			Object name = null;
			Object groupValue = m.get(groupKey.toString());
			if(dateType>0){
				name = Utils.date(Utils.parseDate(groupValue), dateFormats[dateType][1]);
			}else{
				try{
					java.lang.reflect.Method method = SrvApiType.class.getMethod("get"+Utils.ForMat(groupKey.toString())+"$");
					method.setAccessible(true);
					name = method.invoke(SrvApiType.fromMap(m));
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
			map.put("name", name);
			map.put("value", value);
			result.add(map);
		}
		return result;
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static int updateSrvApiType(Map set,Map where){
		if(set.isEmpty())throw new RuntimeException("set为空");
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		return getSrvApiTypeDao().updateSrvApiTypeByConfirm(set, where);
	}
	
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void deleteSrvApiType(Map where){
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		getSrvApiTypeDao().deleteSrvApiTypeByConfirm(where);
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void delete(Long id){
		if(id==null)throw new RuntimeException("id为空");
		getSrvApiTypeDao().removeSrvApiTypeById(id);
	}
	
	
	/**
	 * 保存API分类对象
	 * @param params
	 * @return
	 */
	public SrvApiType save(){
		if(this.getSatId()!=null)
			getSrvApiTypeDao().updateSrvApiType(this);
		else
			return getSrvApiTypeDao().saveSrvApiType(this);
		return this;
	}
	
	
	/**
	 * 更新API分类对象的非空字段,注意跟Service里面的update不一样哦
	 * @param params
	 * @return
	 */
	public int update(){
		return getSrvApiTypeDao().updateSrvApiType$NotNull(this);
	}
	
	
	/**
	 * 删除
	 * @param params
	 * @return
	 */
	public void delete(){
		if(Utils.equals(Utils.config("logic_delete"),"true"))
			getSrvApiTypeDao().removeSrvApiTypeById(this.getSatId());
		else
			getSrvApiTypeDao().deleteSrvApiTypeById(this.getSatId());
	}
	
	/**
	 * 执行事务
	 * @param function
	 */
	public static <T> T execute(Function function){
		return getSrvApiTypeDao().executeTransaction(function);
	}
	/*******************************编号**********************************/	
	/**
	* 编号 [非空]      
	**/
	public Long getSatId(){
		if(this.satId!=null){
			return this.satId;
		}
		return this.satId;
	}
	/**
	* 获取编号格式化(toString)
	**/
	public String getSatId$(){
		String strValue="";
		 strValue=Utils.string(this.getSatId());
	 	 return strValue;
	}
	/**
	* 根据编号反格式化
	**/
	public void setSatId$(String strValue){
		if(Utils.empty(strValue)){
			this.satId=null;
			return;
		}
	 	this.satId=Utils.parseLong(strValue);
	}
	
	/**
	* 编号 [非空]      
	**/
	public void setSatId(Long satId){
		this.satId = satId;
		this.setSeted(F.satId);
	}
	
	
	
	
	/*******************************分类名称**********************************/	
	/**
	* 分类名称 [非空]      
	**/
	public String getSatName(){
		if(this.satName!=null){
			return this.satName;
		}
		return this.satName;
	}
	/**
	* 获取分类名称格式化(toString)
	**/
	public String getSatName$(){
		String strValue="";
		 strValue=Utils.string(this.getSatName());
	 	 return strValue;
	}
	/**
	* 根据分类名称反格式化
	**/
	public void setSatName$(String strValue){
		if(Utils.empty(strValue)){
			this.satName=null;
			return;
		}
	 	this.satName=strValue;
	}
	
	/**
	* 分类名称 [非空]      
	**/
	public void setSatName(String satName){
		this.satName = satName;
		this.setSeted(F.satName);
	}
	
	
	
	
	/*******************************所属分类**********************************/	
	/**
	* 所属分类 [非空] [SrvApiType]     
	**/
	public Long getSatParent(){
		if(this.satParent!=null){
			return this.satParent;
		}
		return this.satParent;
	}
	/**
	* 获取所属分类格式化(toString)
	**/
	public String getSatParent$(){
		String strValue="";
		if(this.getSatParent()!=null){
				strValue+=Utils.string(SrvApiType.getKeyValue(this.getSatParent()));
		}			
	 	 return strValue;
	}
	/**
	* 根据所属分类反格式化
	**/
	public void setSatParent$(String strValue){
		if(Utils.empty(strValue)){
			this.satParent=null;
			return;
		}
		SrvApiType item = SrvApiType.find(strValue);
		if(item!=null){
			this.satParent = Utils.parseLong(item.getSatId());
		}
	}
	
	/**
	* 所属分类 [非空] [SrvApiType]     
	**/
	public void setSatParent(Long satParent){
		this.satParent = satParent;
		this.setSeted(F.satParent);
	}
	
	
	
	
	/**
	* 获取关联对象[API分类]
	**/	 			
 	public SrvApiType get$satParent(){
 		if(this.$satParent!=null)
 			return this.$satParent;
 		com.distribute.framework.model.SrvApiType srvApiType = null;
		if(this.getSatParent()!=null){
 			srvApiType = SrvApiType.get(this.getSatParent());
 		}
 		return srvApiType;
	}
	/*******************************分类标识**********************************/	
	/**
	* 分类标识       
	**/
	public String getSatFlag(){
		if(this.satFlag!=null){
			return this.satFlag;
		}
		return this.satFlag;
	}
	/**
	* 获取分类标识格式化(toString)
	**/
	public String getSatFlag$(){
		String strValue="";
		 strValue=Utils.string(this.getSatFlag());
	 	 return strValue;
	}
	/**
	* 根据分类标识反格式化
	**/
	public void setSatFlag$(String strValue){
		if(Utils.empty(strValue)){
			this.satFlag=null;
			return;
		}
	 	this.satFlag=strValue;
	}
	
	/**
	* 分类标识       
	**/
	public void setSatFlag(String satFlag){
		this.satFlag = satFlag;
		this.setSeted(F.satFlag);
	}
	
	
	
	
	/*******************************修改时间**********************************/	
	/**
	* 修改时间 [非空]      
	**/
	public Date getSatUpdateTime(){
		if(this.satUpdateTime!=null){
			return this.satUpdateTime;
		}
		return this.satUpdateTime;
	}
	/**
	* 获取修改时间格式化(toString)
	**/
	public String getSatUpdateTime$(){
		String strValue="";
		 strValue=Utils.string(Utils.date(this.getSatUpdateTime(),"yyyy-MM-dd HH:mm:ss"));
	 	 return strValue;
	}
	/**
	* 根据修改时间反格式化
	**/
	public void setSatUpdateTime$(String strValue){
		if(Utils.empty(strValue)){
			this.satUpdateTime=null;
			return;
		}
	 	this.satUpdateTime=Utils.date(strValue,"yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	* 修改时间 [非空]      
	**/
	public void setSatUpdateTime(Date satUpdateTime){
		this.satUpdateTime = satUpdateTime;
		this.setSeted(F.satUpdateTime);
	}
	
	
	
	
	/*******************************添加时间**********************************/	
	/**
	* 添加时间 [非空]      
	**/
	public Date getSatAddTime(){
		if(this.satAddTime!=null){
			return this.satAddTime;
		}
		return this.satAddTime;
	}
	/**
	* 获取添加时间格式化(toString)
	**/
	public String getSatAddTime$(){
		String strValue="";
		 strValue=Utils.string(Utils.date(this.getSatAddTime(),"yyyy-MM-dd HH:mm:ss"));
	 	 return strValue;
	}
	/**
	* 根据添加时间反格式化
	**/
	public void setSatAddTime$(String strValue){
		if(Utils.empty(strValue)){
			this.satAddTime=null;
			return;
		}
	 	this.satAddTime=Utils.date(strValue,"yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	* 添加时间 [非空]      
	**/
	public void setSatAddTime(Date satAddTime){
		this.satAddTime = satAddTime;
		this.setSeted(F.satAddTime);
	}
	
	
	
	
	/*******************************状态**********************************/	
	/**
	* 状态 [非空]   1:正常 0:无效    
	**/
	public Short getSatStatus(){
		if(this.satStatus!=null){
			return this.satStatus;
		}
		return this.satStatus;
	}
	/**
	* 获取状态格式化(toString)
	**/
	public String getSatStatus$(){
		String strValue="";
		 if(Utils.equals(Utils.string(this.getSatStatus()),"1"))
			strValue=Utils.string("正常");		 
		 if(Utils.equals(Utils.string(this.getSatStatus()),"0"))
			strValue=Utils.string("无效");		 
	 	 return strValue;
	}
	/**
	* 根据状态反格式化
	**/
	public void setSatStatus$(String strValue){
		if(Utils.empty(strValue)){
			this.satStatus=null;
			return;
		}
		 if(Utils.equals(strValue,"正常"))
		 	this.satStatus=Utils.parseShort("1");
		 if(Utils.equals(strValue,"无效"))
		 	this.satStatus=Utils.parseShort("0");
	}
	
	/**
	* 状态 [非空]   1:正常 0:无效    
	**/
	public void setSatStatus(Short satStatus){
		this.satStatus = satStatus;
		this.setSeted(F.satStatus);
	}
	
	
	
	
	/************LAZY3Q_DEFINE_CODE************/
	/************LAZY3Q_DEFINE_CODE************/
	
	
	/**
	 * 触发器
	 */
	public static void on(Trigger.Index index,final Notify.Listener listener,Trigger.Type... types){
		Notify.on(SrvApiType.class, index, listener, types);
	}
	public static void on(final Notify.Listener listener,String type){
		Notify.on(SrvApiType.class, listener, type);
	}
	/**
	 * 当修改字段时
	 * @param filedName
	 * @param listener
	 */
	public static void on(String filedName,final Notify.Listener listener){
		Notify.on(SrvApiType.class, listener, filedName);
	}
	/**
	 * 当修改字段为某值时
	 * @param filedName
	 * @param value
	 * @param listener
	 */
	public static void on(String filedName,Object value,final Notify.Listener listener){
		if(value==null)return;
		Notify.on(SrvApiType.class, listener, filedName+"."+Utils.md5(""+value));
	}
	public void notify(String type){
		Trigger.on(SrvApiType.class,type, this);
	}
	
	
	/**
	 * 用来获取当有字段关联对象时的获取方式,调用如${SrvApiType.obj.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${SrvApiType.$filedName}获取关联对象
	 */
	public Map getObj(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return SrvApiType.class.getMethod("get$"+Utils.forMat(key.toString())).invoke(SrvApiType.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 用来获取某字段格式化的获取方式,调用如${SrvApiType.fmt.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${SrvApiType.filedName$}获取某字段格式化
	 */
	public Map getFmt(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return SrvApiType.class.getMethod("get"+Utils.ForMat(key.toString()+"$")).invoke(SrvApiType.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 获取查询参数链式串
	 * @return
	 */
	public static @Deprecated M where(){ return new M(0); }
	public static @Deprecated M m(){ return new M(0); }
	public static M where = new M(0,true);
	public static @database(DatabaseNames.distribute_sys) class M extends IbatisMap{
		int type = 0; 
		M linked = null;
		Boolean proxy = false;
		public M set = null;
		public M(int type){
			this.type = type;
			if(this.type==0){
				set = new M(1,true);
				set.linked = this;
			}
		};
		public M(int type,Boolean proxy){
			this.type = type;
			this.proxy=proxy;
		};
		public M proxy(){
			M m = new M(this.type);//当前的对像
			if(this.type==0){
				m.set = new M(1,true);//set对象
				m.set.linked = m;
			}else{
				m.linked=this.linked;
				this.linked.linked=m;
			}
			return m;
		}
		public @Deprecated M set(){			
			M m = this;
			m.linked=new M(1);
			m.linked.linked=m;
			return m.linked;
		};
		public M on(IbatisMap value,C column,String joinColumn){if(proxy)return proxy().on(value,column,joinColumn);this.put(value.getClass().getDeclaringClass().getSimpleName(), value);value.put("on", column.toString());value.put("to", joinColumn);return this;};
		/** 编号 [非空]       **/
		public M satId(Object satId){if(proxy)return proxy().satId(satId);  this.put("satId", satId);return this;};
	 	/** and sat_id is null */
 		public M satIdNull(){if(proxy)return proxy().satIdNull();if(this.get("satIdNot")==null)this.put("satIdNot", "");this.put("satId", null);return this;};
 		/** not .... */
 		public M satIdNot(){if(proxy)return proxy().satIdNot();this.put("satIdNot", "not");return this;};
 		public M satIdNotNull(){if(proxy)return proxy().satIdNotNull();this.put("satIdNot", "not");this.put("satId", null);return this;};
 		public M satIdNot(Object satId){if(proxy)return proxy().satIdNot(satId);this.put("satIdNot", "not");this.put("satId", satId);return this;};
		/** and sat_id <= ? */
		public M satIdMin(Object min){if(proxy)return proxy().satIdMin(min);this.put("satIdMin", min);return this;};
		/** and sat_id >= ? */
		public M satIdMax(Object max){if(proxy)return proxy().satIdMax(max);this.put("satIdMax", max);return this;};
		public M satIdIn(String ids){
			if(proxy)return proxy().satIdIn(ids);  this.put("satIdIn", ids);return this;
		};	
		/** 分类名称 [非空]       **/
		public M satName(Object satName){if(proxy)return proxy().satName(satName);  this.put("satName", satName);return this;};
	 	/** and sat_name is null */
 		public M satNameNull(){if(proxy)return proxy().satNameNull();if(this.get("satNameNot")==null)this.put("satNameNot", "");this.put("satName", null);return this;};
 		/** not .... */
 		public M satNameNot(){if(proxy)return proxy().satNameNot();this.put("satNameNot", "not");return this;};
 		public M satNameNotNull(){if(proxy)return proxy().satNameNotNull();this.put("satNameNot", "not");this.put("satName", null);return this;};
 		public M satNameNot(Object satName){if(proxy)return proxy().satNameNot(satName);this.put("satNameNot", "not");this.put("satName", satName);return this;};
		public M satParent$on(SrvApiType.M value){if(proxy)return proxy().satParent$on(value);this.put("SatParent", value);value.put("on", "sat_parent");return this;};
		/** 所属分类 [非空] [SrvApiType]      **/
		public M satParent(Object satParent){if(proxy)return proxy().satParent(satParent);  this.put("satParent", satParent);return this;};
	 	/** and sat_parent is null */
 		public M satParentNull(){if(proxy)return proxy().satParentNull();if(this.get("satParentNot")==null)this.put("satParentNot", "");this.put("satParent", null);return this;};
 		/** not .... */
 		public M satParentNot(){if(proxy)return proxy().satParentNot();this.put("satParentNot", "not");return this;};
 		public M satParentNotNull(){if(proxy)return proxy().satParentNotNull();this.put("satParentNot", "not");this.put("satParent", null);return this;};
 		public M satParentNot(Object satParent){if(proxy)return proxy().satParentNot(satParent);this.put("satParentNot", "not");this.put("satParent", satParent);return this;};
		public M satParentIn(String ids){
			if(proxy)return proxy().satParentIn(ids);  this.put("satParentIn", ids);return this;
		};	
		/** 分类标识        **/
		public M satFlag(Object satFlag){if(proxy)return proxy().satFlag(satFlag);  this.put("satFlag", satFlag);return this;};
	 	/** and sat_flag is null */
 		public M satFlagNull(){if(proxy)return proxy().satFlagNull();if(this.get("satFlagNot")==null)this.put("satFlagNot", "");this.put("satFlag", null);return this;};
 		/** not .... */
 		public M satFlagNot(){if(proxy)return proxy().satFlagNot();this.put("satFlagNot", "not");return this;};
 		public M satFlagNotNull(){if(proxy)return proxy().satFlagNotNull();this.put("satFlagNot", "not");this.put("satFlag", null);return this;};
 		public M satFlagNot(Object satFlag){if(proxy)return proxy().satFlagNot(satFlag);this.put("satFlagNot", "not");this.put("satFlag", satFlag);return this;};
		/** 修改时间 [非空]       **/
		public M satUpdateTime(Object satUpdateTime){if(proxy)return proxy().satUpdateTime(satUpdateTime);  this.put("satUpdateTime", satUpdateTime);return this;};
	 	/** and sat_update_time is null */
 		public M satUpdateTimeNull(){if(proxy)return proxy().satUpdateTimeNull();if(this.get("satUpdateTimeNot")==null)this.put("satUpdateTimeNot", "");this.put("satUpdateTime", null);return this;};
 		/** not .... */
 		public M satUpdateTimeNot(){if(proxy)return proxy().satUpdateTimeNot();this.put("satUpdateTimeNot", "not");return this;};
 		public M satUpdateTimeNotNull(){if(proxy)return proxy().satUpdateTimeNotNull();this.put("satUpdateTimeNot", "not");this.put("satUpdateTime", null);return this;};
 		public M satUpdateTimeNot(Object satUpdateTime){if(proxy)return proxy().satUpdateTimeNot(satUpdateTime);this.put("satUpdateTimeNot", "not");this.put("satUpdateTime", satUpdateTime);return this;};
 		/** and sat_update_time >= ? */
 		public M satUpdateTimeStart(Object start){if(proxy)return proxy().satUpdateTimeStart(start);this.put("satUpdateTimeStart", start);return this;};			
 		/** and sat_update_time <= ? */
 		public M satUpdateTimeEnd(Object end){if(proxy)return proxy().satUpdateTimeEnd(end);this.put("satUpdateTimeEnd", end);return this;};
		/** 添加时间 [非空]       **/
		public M satAddTime(Object satAddTime){if(proxy)return proxy().satAddTime(satAddTime);  this.put("satAddTime", satAddTime);return this;};
	 	/** and sat_add_time is null */
 		public M satAddTimeNull(){if(proxy)return proxy().satAddTimeNull();if(this.get("satAddTimeNot")==null)this.put("satAddTimeNot", "");this.put("satAddTime", null);return this;};
 		/** not .... */
 		public M satAddTimeNot(){if(proxy)return proxy().satAddTimeNot();this.put("satAddTimeNot", "not");return this;};
 		public M satAddTimeNotNull(){if(proxy)return proxy().satAddTimeNotNull();this.put("satAddTimeNot", "not");this.put("satAddTime", null);return this;};
 		public M satAddTimeNot(Object satAddTime){if(proxy)return proxy().satAddTimeNot(satAddTime);this.put("satAddTimeNot", "not");this.put("satAddTime", satAddTime);return this;};
 		/** and sat_add_time >= ? */
 		public M satAddTimeStart(Object start){if(proxy)return proxy().satAddTimeStart(start);this.put("satAddTimeStart", start);return this;};			
 		/** and sat_add_time <= ? */
 		public M satAddTimeEnd(Object end){if(proxy)return proxy().satAddTimeEnd(end);this.put("satAddTimeEnd", end);return this;};
		/** 状态 [非空]   1:正常 0:无效     **/
		public M satStatus(Object satStatus){if(proxy)return proxy().satStatus(satStatus);  this.put("satStatus", satStatus);return this;};
	 	/** and sat_status is null */
 		public M satStatusNull(){if(proxy)return proxy().satStatusNull();if(this.get("satStatusNot")==null)this.put("satStatusNot", "");this.put("satStatus", null);return this;};
 		/** not .... */
 		public M satStatusNot(){if(proxy)return proxy().satStatusNot();this.put("satStatusNot", "not");return this;};
 		public M satStatusNotNull(){if(proxy)return proxy().satStatusNotNull();this.put("satStatusNot", "not");this.put("satStatus", null);return this;};
 		public M satStatusNot(Object satStatus){if(proxy)return proxy().satStatusNot(satStatus);this.put("satStatusNot", "not");this.put("satStatus", satStatus);return this;};
		public M satStatusIn(String ids){
			if(proxy)return proxy().satStatusIn(ids);  this.put("satStatusIn", ids);return this;
		};	
	 	public M add(String key, Object value) {if(proxy)return proxy().add(key,value);this.put(key, value);return this;}
	 	public M add(F key, Object value) {if(proxy)return proxy().add(key,value);this.put(key.toString(), value);return this;}
	 	public M desc(C key) {if(proxy)return proxy().desc(key);this.put("desc", key.column);return this;}
	 	public M asc(C key) {if(proxy)return proxy().asc(key);this.put("asc", key.column);return this;}
	 	public M desc(String sql) {if(proxy)return proxy().desc(sql);this.put("desc", sql);return this;}
	 	public M asc(String sql) {if(proxy)return proxy().asc(sql);this.put("asc", sql);return this;}
	 	public M definex(String sql) {if(proxy)return proxy().definex(sql);this.put("definex", sql);return this;}
	 	/** 获取所有API分类 **/
		public @api List<SrvApiType> list(Integer size){			
			return getSrvApiTypeList(this,size);
		}
		/** 获取API分类分页 **/
		public @api Page<SrvApiType> page(Integer page,Integer size){			
			return getSrvApiTypePage(page, size , this);
		}
		/** 根据查询条件取API分类 **/
		public @api SrvApiType get(){			
			return getSrvApiType(this);
		}
		/** 获取API分类数 **/
		public @api Long count(){			
			return getSrvApiTypeCount(this);
		}
		/** 获取API分类表达式 **/
		public @api <T> T eval(String strEval){			
			return getSrvApiTypeEval(strEval,this);
		}
		/** 获取API分类统计 **/
		public @api List<Map> stats(C sumKey,C groupKey,int dateType){			
			return getSrvApiTypeStats(this,sumKey,groupKey,dateType);
		}
		/** 获取API分类统计 **/
		public @api List<Map> stats(C sumKey,C groupKey){			
			return getSrvApiTypeStats(this,sumKey,groupKey,-1);
		}
		/** 根据条件更新 **/
		public @api int update(){			
			M where = null;
			M set = null;
			if(this.type==0){
				if(this.linked==null)throw new RuntimeException("未发set");
				where = this;
				set = this.linked;
			}else{
				if(this.linked==null)throw new RuntimeException("未发where条件");
				set = this;
				where = this.linked;
			}
			return updateSrvApiType(set,where);
		}
		/** 根据条件删除 **/
		public @api void delete(){			
			deleteSrvApiType(this);
		}
	}
	
	public static class Param extends M{
		public Param(int type) {
			super(type);
		}
		public Param(int type, Boolean proxy) {
			super(type, proxy);
		}
	}
	
	/** 对象的字段描述 **/
	public static class F{
		/** 编号 [非空]       **/
		public final static @type(Long.class)  String satId="satId";
		/** 分类名称 [非空]       **/
		public final static @type(String.class)  String satName="satName";
		/** 所属分类 [非空] [SrvApiType]      **/
		public final static @type(Long.class)  String satParent="satParent";
		/** 分类标识        **/
		public final static @type(String.class)  String satFlag="satFlag";
		/** 修改时间 [非空]       **/
		public final static @type(Date.class)  String satUpdateTime="satUpdateTime";
	 	/** and sat_update_time >= ? */
 		public final static @type(Date.class) String satUpdateTimeStart="satUpdateTimeStart";
 		/** and sat_update_time <= ? */
 		public final static @type(Date.class) String satUpdateTimeEnd="satUpdateTimeEnd";
		/** 添加时间 [非空]       **/
		public final static @type(Date.class)  String satAddTime="satAddTime";
	 	/** and sat_add_time >= ? */
 		public final static @type(Date.class) String satAddTimeStart="satAddTimeStart";
 		/** and sat_add_time <= ? */
 		public final static @type(Date.class) String satAddTimeEnd="satAddTimeEnd";
		/** 状态 [非空]   1:正常 0:无效     **/
		public final static @type(Short.class)  String satStatus="satStatus";
	 	public static String get(String name){
			try {
				Field field = F.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	/** 对象的数据库字段描述 **/
	public static enum C{
		satId("sat_id"),
		satName("sat_name"),
		satParent("sat_parent"),
		satFlag("sat_flag"),
		satUpdateTime("sat_update_time"),
		satAddTime("sat_add_time"),
		satStatus("sat_status"),
		count("count");
		String column;
		C(String column){
			this.column = column;
		}
		public String toString(){
			return this.column;
		}
		public static String get(String name){
			try {
				Field field = C.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	
	
	
	/**
	* 获取API分类数据
	**/
	public static Object getData(Object param){
		if(param==null)
			return null;
		Object value = null;
		if(param.getClass()==Long.class)
			value = SrvApiType.get((Long)param);
		else if(param instanceof java.util.Map){
			java.util.Map params = (Map) param;
			if(params.get("size")==null)
				value = SrvApiType.getSrvApiType(params);
			else
				value = SrvApiType.getSrvApiTypeList(params, (Integer) params.get("size"));
		}else if(param.getClass()==Long.class )
			value =  SrvApiType.where().satId(param).get();
		else if(!Utils.empty(param.toString()))
			value = SrvApiType.get(Long.valueOf(param.toString()));
		return value;
	}
	
	/**对象转json**/
	public Map toJSON(){
		return toJSON(false);
	}
	public Map toJSON(boolean simple){
		Map map = new HashMap();
		map.put("id",this.getSatId());
		Utils.fms(map,simple?"id":"satId",this.getSatId(),this.getSatId$());
		Utils.fms(map,simple?"name":"satName",this.getSatName(),this.getSatName$());
		Utils.fms(map,simple?"parent":"satParent",this.getSatParent(),this.getSatParent$());
		Utils.fms(map,simple?"flag":"satFlag",this.getSatFlag(),this.getSatFlag$());
		Utils.fms(map,simple?"updateTime":"satUpdateTime",this.getSatUpdateTime(),this.getSatUpdateTime$());
		Utils.fms(map,simple?"addTime":"satAddTime",this.getSatAddTime(),this.getSatAddTime$());
		Utils.fms(map,simple?"status":"satStatus",this.getSatStatus(),this.getSatStatus$());
		if(this.suffix!=null)map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOJSON************/
		/************LAZY3Q_DEFINE_TOJSON************/
		return map;
	}
	/**对象转map**/
	public Map toMap(){
		Map map = new HashMap();
		map.put("satId",this.getSatId());
		map.put("satName",this.getSatName());
		map.put("satParent",this.getSatParent());
		map.put("satFlag",this.getSatFlag());
		map.put("satUpdateTime",this.getSatUpdateTime());
		map.put("satAddTime",this.getSatAddTime());
		map.put("satStatus",this.getSatStatus());
		map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOMAP************/
		/************LAZY3Q_DEFINE_TOMAP************/
		return map;
	}
	/**map转对象**/
	public static SrvApiType fromMap(Map map){
		SrvApiType srvApiType = new SrvApiType();
		srvApiType.satId = Utils.parseLong(map.get("satId"));
		srvApiType.satName = Utils.parseString(map.get("satName"));
		srvApiType.satParent = Utils.parseLong(map.get("satParent"));
		srvApiType.satFlag = Utils.parseString(map.get("satFlag"));
		srvApiType.satUpdateTime = Utils.parseDate(map.get("satUpdateTime"));
		srvApiType.satAddTime = Utils.parseDate(map.get("satAddTime"));
		srvApiType.satStatus = Utils.parseShort(map.get("satStatus"));
		return srvApiType;
	}
	
	
	
	/**字段设置标记队列**/
	private Map<String,Boolean> seted=new HashMap();
	public Boolean getSeted(String key){
		return seted.get(key);
	}
	public void setSeted(String key){
		seted.put(key,true);
	}
	/**同步未set的字段**/
	public void mergeSet(SrvApiType old){
		Field[] fields = this.getClass().getDeclaredFields();
		try {
			for(Field field:fields){
				String key = field.getName();
				if(seted.get(key)==null && field.getAnnotation(column.class)!=null){
					field.setAccessible(true);
					field.set(this, field.get(old));					
				}
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
		
	/**自定义变量存储**/
	private Map values=new HashMap();
	public Map getValues(){
		return values;
	}
	public void setValues(String name,Object value){
		values.put(name,value);
	}
	
	/**分表时的表名后缀**/
	private String suffix;
	public String getSuffix() {
		return suffix;
	}
	public void setSuffix(String suffix) {
		this.suffix = suffix;
	}
	/**获取数据库名称**/
	public static String getDataBaseName(){
		return Utils.config("spring.datasource.distribute_sys.name");
	}
	
	public static String getIcon(){
		return "/images/icons/20088256421631277807.png";
	}
	public static String getIconfont(){
		return "icon-icon05";
	}
	public static enum ACT{
		列表,添加,修改,详情
	};
	public static String getUrl(ACT act,SrvApiType.M params){
		if(params==null)params=new SrvApiType.M(0);
		params.remove("joins");
		params.remove("definexs");
		params.remove("distinct");
		String strUrl = "/admin/api/apitype.edit.html?";
		if(params.get("satId")!=null){
			strUrl+="&id="+Utils.encode(""+params.get("satId"),Utils.UTF8);
		}
		if(act==ACT.列表){
			strUrl = "/admin/api/apitype.html?1=1";
		}else if(act==ACT.添加){
			strUrl+="&edittype=insert";
		}else if(act==ACT.修改){
			strUrl+="&edittype=update";
		}else if(act==ACT.详情){
			strUrl+="&edittype=detail";
		}		
		if(params!=null){
			for(Object key:params.keySet()){
				strUrl+="&"+key+"="+Utils.encode(""+params.get(key),Utils.UTF8)+"";
			}
		}
		return strUrl;
	}
	public String getDetailUrl(){
		return this.getUrl(ACT.详情, where.satId(this.getId()));
	}
	
	/**
	* 转跳到当前地址
	**/
	public static Protocol redirect(SrvApiType.ACT act,SrvApiType.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_REDIRECT");
		protocol.set("url",SrvApiType.getUrl(act, params));
		return protocol;
	}
	/**
	* 打开一个新的tab页面
	**/
	public static Protocol href(SrvApiType.ACT act,SrvApiType.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_HREF");
		protocol.set("url",SrvApiType.getUrl(act, params));
		protocol.set("title",act.name());
		return protocol;
	}
	/**
	* 显示一个消息框，并且关闭当前的对话框
	**/
	public static Protocol message(String message){
		Protocol protocol = Protocol.create(true,null,"ACT_MESSAGE");
		protocol.set("message",message);
		return protocol;
	}
	
	
	static com.distribute.framework.dao.ISrvApiTypeDao getSrvApiTypeDao(){
		return Utils.getBean("srvApiTypeDao");
	};
	
}